﻿using Covid.Client.Services;
using Covid.Shared.Dtos;
using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;

namespace Covid.Client.Pages
{
    public class EmployeeDetailBase:ComponentBase
    {

        [Inject]
        public NavigationManager NavigationManager { get; set; }

        [Parameter]
        public string EmployeeId { get; set; }


        public EmployeeDto Employee { get; set; } = new EmployeeDto();


        //v1
        /// <summary>
        /// 注入HttpClient
        /// </summary>
        //[Inject]
        //public HttpClient HttpClient { get; set; }


        //v2
        [Inject]
        public IEmployeeService EmployeeService { get; set; }




        /// <summary>
        /// 生命周期方法 ，Component被初始化之后会调用这个方法
        /// </summary>
        /// <returns></returns>
        protected override async Task OnInitializedAsync()
        {

            //v1
            //Employee = await HttpClient.GetFromJsonAsync<EmployeeDto>($"api/department/1/employee/{EmployeeId}");

            //v2
            Employee = await EmployeeService.GetOneForDepartmentAsync(1, int.Parse(EmployeeId));

            await base.OnInitializedAsync();
        }



        protected void button_Click() {
            Employee.Name = "重置了！！！";
        }


        /// <summary>
        /// 返回
        /// </summary>
        public void GoBack() {
            NavigationManager.NavigateTo("employeeoverview");
        }

    }
}
